package org.shopen.ai.puremvc.view.project
{
	import mx.collections.ArrayCollection;
	
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.mediator.Mediator;
	import org.shopen.ai.puremvc.ApplicationConstants;
	import org.shopen.ai.puremvc.model.project.ProjectsProxy;
	import org.shopen.ai.puremvc.view.project.components.StepBox;

	public class StepBoxMediator extends Mediator
	{
		public static const NAME : String = "StepBoxMediator";
		
		protected function get stepBox() : StepBox
		{
			var result : StepBox = viewComponent as StepBox;
			return result;
		}
		
		public function StepBoxMediator(viewComponent:Object=null)
		{
			super(StepBoxMediator.NAME, viewComponent);
		}
		
		override public function getMediatorName():String
		{
			return StepBoxMediator.NAME;
		}
		
		override public function onRegister():void
		{
			initializeSteps();
		}
		
		protected function initializeSteps() : void
		{
			var proxy : ProjectsProxy = facade.retrieveProxy(ProjectsProxy.NAME) as ProjectsProxy;
			this.stepBox.steps = proxy.getCurrentProject().steps;
			this.stepBox.selectedStep = -1;
		}
		
		override public function listNotificationInterests():Array
		{
			return [ApplicationConstants.CHANGE_STEP];
		}		
		
		override public function handleNotification(notification:INotification):void
		{
			var name : String = notification.getName();
			switch (name)
			{
				case ApplicationConstants.CHANGE_STEP:
					handleStepChanged(notification);
					break;
			}
		}
		
		protected function handleStepChanged(notification : INotification) : void
		{
			var step : int = notification.getBody() as int;
			stepBox.selectedStep = step;
		}
	}
}